package com.sam.lib.store;

import android.content.Context;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;


public class StoreManage {

    private final static String TAG = "StoreManage";

    private static IStore mStore = null;

    private static Context mContext;

    public static void initialize(Context context, IStore store) {
        mContext = context.getApplicationContext();
        mStore = store;
    }

    public static Context getContext() {
        if (mContext == null) {
            throw new RuntimeException("You should Call StoreManage.initialize() first.");
        }
        return mContext;
    }

    private static IStore getStore() {
        if (mStore != null) {
            return mStore;
        }
        throw new RuntimeException("You should Call StoreManage.initialize() first.");
    }

    public static void putStringSet(Context context, int mode, String name, String key, Set<String> values) {
        getStore().putStringSet(context, name, mode, key, values);
    }

    public static Set<String> getStringSet(Context context, int mode, String name, String key) {
        return getStore().getStringSet(context, name, mode, key, new HashSet<String>());
    }

    public static Set<String> getStringSet(Context context, int mode, String name, String key, Set<String> def) {
        return getStore().getStringSet(context, name, mode, key, def);
    }

    public static void putString(Context context, int mode, String name, String key, String value) {
        getStore().putString(context, name, mode, key, value);
    }

    public static String getString(Context context, int mode, String name, String key) {
        return getStore().getString(context, name, mode, key);
    }

    public static String getString(Context context, int mode, String name, String key, String def) {
        return getStore().getString(context, name, mode, key, def);
    }

    public static void putLong(Context context, int mode, String name, String key, long value) {
        getStore().putLong(context, name, mode, key, value);
    }

    public static long getLong(Context context, int mode, String name, String key) {
        return getStore().getLong(context, name, mode, key);
    }

    public static long getLong(Context context, int mode, String name, String key, long def) {
        return getStore().getLong(context, name, mode, key, def);
    }

    public static void putFloat(Context context, int mode, String name, String key, float value) {
        getStore().putFloat(context, name, mode, key, value);
    }

    public static float getFloat(Context context, int mode, String name, String key) {
        return getStore().getFloat(context, name, mode, key);
    }

    public static float getFloat(Context context, int mode, String name, String key, float def) {
        return getStore().getFloat(context, name, mode, key, def);
    }

    public static void putInt(Context context, int mode, String name, String key, int value) {
        getStore().putInt(context, name, mode, key, value);
    }

    public static int getInt(Context context, int mode, String name, String key) {
        return getStore().getInt(context, name, mode, key);
    }

    public static int getInt(Context context, int mode, String name, String key, int def) {
        return getStore().getInt(context, name, mode, key, def);
    }

    public static void putBoolean(Context context, int mode, String name, String key, boolean value) {
        getStore().putBoolean(context, name, mode, key, value);
    }

    public static boolean getBoolean(Context context, int mode, String name, String key) {
        return getStore().getBoolean(context, name, mode, key, false);
    }

    public static boolean getBoolean(Context context, int mode, String name, String key, boolean def) {
        return getStore().getBoolean(context, name, mode, key, def);
    }

    public static Map<String, ?> getAll(Context context, String name, int mode) {
        return getStore().getAll(context, name, mode);
    }

    public static void clearAll(Context context, String name, int mode) {
        getStore().clearAll(context, name, mode);
    }

    public static void put(Context context, int mode, String name, String key, Integer value) {
        getStore().putInt(context, name, mode, key, value);
    }

    public static void put(Context context, int mode, String name, String key, String value) {
        getStore().putString(context, name, mode, key, value);
    }

    public static void put(Context context, int mode, String name, String key, Float value) {
        getStore().putFloat(context, name, mode, key, value);
    }

    public static void put(Context context, int mode, String name, String key, Long value) {
        getStore().putLong(context, name, mode, key, value);
    }

    public static void put(Context context, int mode, String name, String key, Boolean value) {
        getStore().putBoolean(context, name, mode, key, value);
    }

    public static void put(Context context, int mode, String name, String key, Set<String> value) {
        getStore().putStringSet(context, name, mode, key, value);
    }


    public static void migrate(Context context, IStore from, String fromName, int fromMode, IStore to, String toName, int toMode) {
        to.migrate(context, toName, toMode, from, fromName, fromMode);
    }

    public static void migrate(Context context, String name, int mode, IStore from, IStore to) {
        to.migrate(context, name, mode, from, name, mode);
    }

}
